'use strict';

import Base from './base.js';

export default class extends Base {
    /**
     * index action
     * @return {Promise} []
     */

    async indexAction() {
        //auto render template file index_index.html
        let model = this.model('users_table_copy');
        let datas = await model.field('name,tel').select();
        this.assign('datas', datas);
        return this.display();
    }

    /* 参考 https://thinkjs.org/zh-cn/doc/2.2/controller.html#*/
    async listAction(self) {
        let model = self.model('users_table');

        //return this.success(data);
        /*let insertId = await model.add({
            name: '凤杰',
            tel: '12345678901'
        });*/

        /* let result = await model.thenAdd({
             name: '凤杰1',
             tel: '12345678901'
         }, {
             name: '凤杰1'
         });

         let datas = await model.field('name,tel').select();
         console.log('result', result);*/

        /*let affectedRows = await model.where({
            state: '3'
        }).update({
            state: '2'
        });*/
        /*let affectedRows = await model.where('1=1').update({
            state: '2'
        });*/
        /*  let data = await model.limit(2).where({
             name: '凤杰x'
         }).select();

          console.log(think.isEmpty(data));*/
        let data = await model.page(this.get('page'), 2).countSelect();
        console.log('data', data)
            /*let data = await model.where({
                state: '3'
            }).delete();*/
            /*let data = await self.model('users_table').addUser({
                name: 'xx',
                tel: '123',
            });*/

        return this.json(data);

    }

}
